"""
元数据模式定义
"""

import json
from pydantic import BaseModel
from typing import List, Dict, Any, Optional
from datetime import datetime


class DocumentMetadata(BaseModel):
    """文档元数据"""
    section_id: int
    chunk_id: int
    source: str
    title: str
    category: str
    keywords: List[str]
    chunk_length: int
    
    def to_chroma_metadata(self) -> Dict[str, Any]:
        """转换为Chroma兼容的元数据格式"""
        return {
            "section_id": self.section_id,
            "chunk_id": self.chunk_id,
            "source": self.source,
            "title": self.title,
            "category": self.category,
            "keywords": json.dumps(self.keywords, ensure_ascii=False),
            "chunk_length": self.chunk_length
        }


class KnowledgeSearchResult(BaseModel):
    """知识检索结果"""
    content: str
    metadata: DocumentMetadata
    similarity_score: float


class KnowledgeProcessingStats(BaseModel):
    """知识库处理统计"""
    sections_count: int
    documents_count: int
    processing_time: str
    vector_db_path: str
    knowledge_type: str